home *** CD-ROM | disk | FTP | other *** search
- package sub_arctic.demo_apps;
-
- import sub_arctic.input.event;
- import sub_arctic.input.pick_collector;
- import sub_arctic.input.user_info_holder;
- import sub_arctic.input.move_draggable;
- import sub_arctic.lib.icon;
- import sub_arctic.lib.base_interactor;
- import sub_arctic.lib.manager;
- import sub_arctic.lib.interactor;
- import sub_arctic.anim.simple_animatable;
- import sub_arctic.anim.simple_transition;
- import sub_arctic.anim.line_trajectory;
- import sub_arctic.anim.linear_pacer;
- import sub_arctic.anim.time_interval;
- import sub_arctic.output.loaded_image;
-
- import java.awt.Point;
- import java.net.MalformedURLException;
-
- /**
- * This is the little class that represents the iconic form of a message.
- */
-
- public class message_icon extends icon implements move_draggable, simple_animatable {
- /**
- * The message we represent.
- */
- protected message[] _msg;
- /**
- * Our applet
- */
- mail_test _applet;
- /**
- * The image we are using
- */
- protected loaded_image envelope_image=null;
- /**
- * This is true if we are originating from the headers.
- */
- public boolean _from_headers;
-
- /**
- * Construct an icon.
- */
- public message_icon(message[] m, int global_x, int global_y,
- base_interactor my_parent,
- mail_test a,
- boolean fh) {
- super(null);
- _msg=m;
- _applet=a;
- _from_headers=fh;
- if (envelope_image==null) {
- try {
- envelope_image=manager.
- load_doc_image(_applet,"./images/envelope.gif");
- } catch (MalformedURLException e) {
- manager.handle_unexpected_exception(e);
- }
- }
- set_image(envelope_image);
- my_parent.add_child(this);
- set_x(global_x-(envelope_image.width()/2));
- set_y(global_y-(envelope_image.height()/2));
- }
- /**
- * Move ourselves to a new location.
- */
- protected void reposition(int x, int y) {
- set_x(x);
- set_y(y);
- }
- /**
- * Start a drag
- */
- public boolean drag_start(event evt, int x, int y, int grab_x, int grab_y,
- Object user_info) {
- reposition(x,y);
- return true;
- }
- /**
- * Continue a drag.
- */
- public boolean drag_feedback(event evt,int x, int y, int start_x,
- int start_y, int grab_x, int grab_y,
- Object user_info) {
- reposition(x,y);
- return true;
- }
- /**
- * End a drag.
- */
- public boolean drag_end(event evt,int x, int y, int start_x,
- int start_y, int grab_x, int grab_y,
- Object user_info) {
- pick_collector picker;
- int i;
- user_info_holder uih;
- interactor field, list;
- boolean found_playing_field=false, found_todo_list=false;
-
- /* the object we are going to be looking for is the
- playing field for messages */
- field=_applet.playing_field();
- list=_applet.todo_listbox();
- reposition(x,y);
- /* we might want to pop up a mail message now ... run a pick*/
- picker=new pick_collector();
- /* out parent is the top_level so we pick in that */
- parent().pick(evt.global_x(), evt.global_y(), picker);
- /* see if the object we are looking for is in the list */
- for (i=0; i<picker.num_picks(); ++i) {
- /* get the ith element */
- uih=picker.pick(i);
- /* is this the field?*/
- if (field==uih.obj) {
- found_playing_field=true;
- break;
- }
- /* is this the box */
- if (list==uih.obj) {
- found_todo_list=true;
- break;
- }
- }
- /* ok did we get it ?*/
- if ((found_playing_field==false) &&
- (found_todo_list==false)) {
- bad_drag(start_x, start_y,x,y);
- } else {
- /* are we coming from the headers? */
- if (_from_headers) {
- /* which did we find? */
- if (found_playing_field) {
- drop_on_playing_field(evt);
- } else {
- drop_on_listbox(evt);
- }
- } else {
- /* we are coming from the list */
- }
- }
- return true;
- }
- /**
- * This function gets called when the transition starts.
- * @param Object start_obj the start time mapped through the trajectory
- */
- public void start_transition(Object start_obj) {
- /* extract the object */
- Point pt=(Point)start_obj;
- /* reposition this icon */
- reposition(pt.x,pt.y);
- }
- /**
- * This function gets called as the transition progress. You receive
- * a time interval mapped through the pacing and trajectory functions.
- * @param Object start_obj the start time mapped through the trajectory
- * @param Object end_obj the end time mapped through the trajectory
- */
- public void transition_step(Object start_obj, Object end_obj) {
- /* extract the object */
- Point pt=(Point)end_obj;
- /* reposition this icon */
- reposition(pt.x,pt.y);
- }
- /**
- * This function is called when a transition ends. You receive
- * a time interval mapped through the pacing and trajectory functions.
- * @param Object start_obj the start time mapped through the trajectory
- * @param Object end_obj the end time mapped through the trajectory
- */
- public void end_transition(Object start_obj, Object end_obj) {
- /* extract the object */
- Point pt=(Point)end_obj;
- /* reposition this icon */
- reposition(pt.x,pt.y);
- /* remove us from the tree */
- parent().remove_child(this);
- }
- /**
- * This function gets called when the user drags us somewhere that doesn't
- * make sense. We want to return the origin of the drag.
- */
- public void bad_drag(int origin_x, int origin_y, int current_x,
- int current_y) {
- long now=time_interval.now(),duration;
- double distance, xdist, ydist;
-
- /* how far is it in each dimension?*/
- xdist=(double)(origin_x-current_x);
- ydist=(double)(origin_y-current_y);
- /* square each dimension */
- xdist=xdist*xdist;
- ydist=ydist*ydist;
- /* compute the square root */
- distance=Math.sqrt(xdist + ydist);
- /* we want 800 pixels to equal 1 second */
- distance/=800.0;
- distance*=1000.0;
- /* round to an int to get the value of the number of ms */
- duration=(long)distance;
-
- /* create pacer ... we want a simple linear mapping */
- linear_pacer pace=new linear_pacer();
- /* move along the line from now to origin */
- line_trajectory traj=new line_trajectory(current_x, current_y,
- origin_x, origin_y,
- pace);
- /* the time interval is 100ms + duration whic starts 100ms from now*/
- time_interval interval=new time_interval(now+100,now+200+duration);
- /* tell the animation system we are good to go */
- simple_transition trans=new simple_transition(this,interval,traj);
- manager.animation.schedule_transition(trans);
- }
- /**
- * This method gets called when we get dropped on the playing field.
- */
- public void drop_on_playing_field(event evt) {
- int global_x=evt.global_x(),global_y=evt.global_y();
- Point pt=new Point(global_x,global_y);
- int i;
- message m;
-
- /* do this before we take ourselves out of the hierarchy */
- interactor field=_applet.playing_field();
- /* remove the icon and shove in the display */
- parent().remove_child(this);
- /* set the new coords to be our coords */
- pt=field.global_to_local(pt);
-
- /* loop over all our messages */
- for (i=0; i<_msg.length; ++i) {
- m=_msg[i];
- /* build a message display from this message */
- message_display display=new message_display(m,_applet);
- header_listbox.size_message(display);
- /* this belongs to the playing field */
- field.add_child(display);
- display.set_x(pt.x - (display.w()/2) + (i*5));
- display.set_y(pt.y + (i*5));
- }
- }
- /**
- * This method is called when we have detected a drop on the listbox.
- */
- public void drop_on_listbox(event evt) {
- event e=new event(evt); // make a copy
- todo_listbox lb=(todo_listbox)_applet.todo_listbox();
- message m;
- int i;
-
- for (i=0; i<_msg.length; ++i) {
- m=_msg[i];
- /* convert to its coordinate system */
- e.global_to_local(lb);
- lb.insert_at_point(m,e.local_y(),-1,-1);
- }
- /* take us off the scrren */
- parent().remove_child(this);
- }
- }
- /*=========================== COPYRIGHT NOTICE ===========================
-
- This file is part of the subArctic user interface toolkit.
-
- Copyright (c) 1996 Scott Hudson and Ian Smith
- All rights reserved.
-
- The subArctic system is freely available for most uses under the terms
- and conditions described in
- http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html
- and appearing in full in the lib/interactor.java source file.
-
- The current release and additional information about this software can be
- found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
-
- ========================================================================*/
-